 module.exports = function (UC, source, config, ArFor, cache, package) {


     UserControl = UC;

     var router = function (req, res, next) {

         var params = req.params;

         var direction = "ltr";

         var manifest = false;

         var manifestjs = false;

         var app = false;
         var _cache = true;
         var UserAgent = req.UserAgent;

         if (params.isMobile) {
             UserAgent.isMobile = true;
         }
         if (params.manifest) {
             app = true;
             manifest = true;
         }

         if (params.manifestjs) {
             app = true;

             var manifest = true;

             manifestjs = true;
         }
         if (params.cache) {
             _cache = false;
         }
         /*
         var host = req.host;
         if (host == 'localhost') {
            manifest=false;
         }
         */


         var Open_Admin_Page = function (jurisdictions) {

             var filekey =   package.id + req.originalUrl + '/' + package.version + "." + (config.id + "").split('').join('.') + "." + config.version

             filekey = filekey.replace('//', '/');

             var manifest_id = cache.GetTemplateID(filekey);

             var version = (UserAgent.isMobile ? 'M' : 'P') + '.' + package.version + '.' + (config.id + "").split('').join('.') + "." + config.version;

             var File = cache.GetTemplateID(filekey) + ".html";
             var jlanguage = config.jlanguage;
             var obj = {
                 Save: {
                     file: File,
                     manifest: manifest ? {
                         js: manifestjs,
                         url: config.getdomain(req, req.path),
                         version: version,
                         file: manifest_id,
                         id: manifest_id,
                         vue: true,
                     } : null,
                     domain: config.getdomain(req, req.path)
                 },
                 Drive: {
                     manifest: params.manifest,
                     name: params.name,
                 },
                 sys_id: package.id,
                 version: version,
                 icon: config.icon,
                 originalUrl: req.path,
                 title: jlanguage.getval(config.name, config._language),
                 direction: direction,
                 jurisdictions: jurisdictions,
                 UserAgent: req.UserAgent
             };
             if (manifest && req.url.indexOf('/manifest.appcache') > 0 || req.url.indexOf('/manifest-sw.js') > 0) {
                 cache.openmanifes(manifest_id, function (str, error) {
                     if (error) {
                         cache.Render({
                             id: package.id,
                             file: './jviews/index.ejs'
                         }, obj, function () {
                             cache.openmanifes(manifest_id, function (str, error) {
                                 if (manifestjs) {
                                     res.Js(str)
                                 } else {
                                     res.set('mime-type', 'text/cache-manifest');
                                     res.send(str)
                                 }
                             }, manifestjs)
                         });
                     } else {
                         if (manifestjs) {
                             res.Js(str)
                         } else {
                             res.send(str)
                         }
                     }
                 }, manifestjs)
             } else {
                 var etag = config.getETag(filekey);
                 if (etag == req.getHeader('if-none-match')) {
                     req.notModified()
                     return;
                 }
                 if (_cache) {
                     res.etag_key = etag;
                 }
                 cache.exists((_cache ? '' : 'no_cache_' + File), function (off) {
                     if (off) {
                         return
                     }
                     cache.Render({
                         id: package.id,
                         file: './jviews/index.ejs'
                     }, obj, function (html) {

                         //res.setHeader("Service-Worker-Allowed", '.');

                         res.Html(html)
                     });
                 }, res)
             };
         };

         Open_Admin_Page([])
     }

     return router;
 };